clear all
set mem 50m
* cd "..."
use "DATA_COMPILED_ATOP_20151118.dta"
set more off 

label var interaction2 "Troops $\times$ Troops Spatial Mean"
label var w_lnallies "Host-State Allies (Spatial Mean)"
label var w_lnusally "US Allies (Spatial Mean)"

kountry ccode, from(cown) geo(cow)

format lntroops defenseburden lntroops_spmean %9.2fc

	

// Full Sample
xtset ccode year
set more off
eststo clear
#delimit ;
	//	All States
xtpcse defenseburden cl.lntroops##cl.lntroops_spmean l.spatial_lag l.polity 
	l.growth l.lntpop l.IMR l.threat_environment war movav3 borderstates civilwar 
	l.meanregionalallies l.meanregionalusallies if year<2004 , 
	corr(ar1) pairwise ;
	
	#delimit cr
	
	set matsize 10000
	margins, at((mean) _all war=0 civilwar=0 (median) borderstates l.lntroops=(0(.5)13) l.lntroops_spmean=(0(.5)13)) post
	matrix list r(b)
	matrix b=r(b)'
	matrix list b
	matrix at=r(at)
	matrix list at
	matrix pr=b,at
	matrix list pr
	clear
	svmat pr
	
	rename pr1 xb 
	rename pr2 troops
	rename pr3 troops_spmean
	
	twoway contour xb troops_spmean troops,  ccuts(0 1 2 3 4 5 6 7 8 9 10)  ///
	xlabel(0(1)13) ylabel(0(1)13) xtitle("ln(Troops)") ytitle("ln(Troops Spatial Mean)") ztitle("Predicted Defense Burden (%)")
	graph export "defburden_contour.pdf", replace
